* Draw main scatter plots *
	
/* firms rejecting deltap or deltas tests only */ 
do "modules/__drawgraph.do"
do "modules/rdbwselect2a.ado"
sysdir set PLUS ado_rdrobust920/plus

local sample_file_name = "sample_090122.dta"

global firstday_after = "15mar2019"
cap mkdir ../temp
graph drop _all
cap drop thebidder
cap graph drop treatment_s
use ../tmp/`sample_file_name', clear
set type double
gen thebidder = 1 if firm_treatment == 1 & ftt_ts1s > 1.64 & ftt_ts1s < . /*& fy_con != 2020*/
local endpd = "31mar2021"
** 	args ii st_fy en_fy gname gtitle msz st_mdybid ed_mdybid graphtableop bwselector
rddelta1xgp "provide_table" "2011" "." "left" "Before" "vsmall" "td(01apr2015)" "td(15feb2019)" "onebw_replace" "msetwo"
est store before_s_treatment
rddelta1xgp "provide_table_add" "2011" "." "right" "After" "vsmall" "td($firstday_after)" "td(`endpd')" "onebw" "msetwo"
est store after_s_treatment
graph combine left right, xsize(6) ysize(4) graphregion(c(white)) /*note("by `endpd'", size(vsmall))*/ ///
	title("Treatment", size(medlarge)) scale(1.1) imargin(small) name(treatment_s)
graph export "../graph/Treatmentfirms_s_by`endpd'_condition_$firstday_after.png", as(png) width(4096) replace

	
cap drop thebidder
cap graph drop control_s
use ../tmp/`sample_file_name', clear
local endpd = "31mar2021"
gen thebidder = 1 if firm_treatment == 0 & g28_plus != 21 & g28_plus != 24 & ftt_ts1s > 1.64 & ftt_ts1s < . /*& fy_con != 2020*/
rddelta1xgp "provide_table" "2011" "." "left" "Before" "vsmall" "td(01apr2015)" "td(15feb2019)" "onebw" "msetwo"
est store before_s_control
rddelta1xgp "provide_table" "2011" "." "right" "After" "vsmall" "td($firstday_after)" "td(`endpd')" "onebw" "msetwo"
est store after_s_control

graph combine left right, xsize(6) ysize(4) graphregion(c(white)) /*note("by `endpd'", size(vsmall))*/ ///
	title("Control", size(medlarge)) scale(1.1) imargin(small) name(control_s)
/**/graph export "../graph/Controlfirms_s_by`endpd'_condition_$firstday_after.png", as(png) width(4096) replace

estout before_s_treatment after_s_treatment before_s_control after_s_control using ../tables/main_rd_test_s.tex, replace ///
	cells(none) ///
	stats(tau_bc_l se_tau_rb h_l /*b_l *kernel bwselect*/ N_l, fmt(/*%6.0g*/3  3 3 /*3 0 0*/ "%9.0fc",star(tau_bc_l)) ///
		labels(`"\raisebox{0mm}{$\hat{\beta}$}"' `" "' `"\it{h}"' `"Obs."') layout(@ (@) @ @) ) 


	
/* delta_p is the running variable */
*graph drop _all
set type double
do "modules/__drawgraph.do"
do "modules/rdbwselect2a.ado"
cap graph drop treatment_p
cap drop thebidder
use ../tmp/`sample_file_name', clear
replace ldelta1s_p = . if score_n == 0 /* temporary added 24Aug23*/
gen thebidder = 1 if firm_treatment== 1 /*& id ~= 65459*/ & ftt_ts1p < -1.64
local endpd = "31mar2021"
rddelta1pgp "provide_table" "2013" "2020" "before" "Before" "vsmall" "td(1apr2015)" "td(15feb2019)" "onebw_replace" "msetwo"
est store before_p_treatment
rddelta1pgp "provide_table" "2011" "." "after" "After" "vsmall" "td($firstday_after)" "td(`endpd')" "onebw" "msetwo"
est store after_p_treatment
graph combine before after, xsize(6) ysize(4) graphregion(c(white)) ///
	title("Treatment", size(medlarge)) scale(1.1) imargin(small) name(treatment_p)
graph export "../graph/Treatmentfirms_p_by`endpd'_condition_$firstday_after.png", as(png) width(4096) replace


cap graph drop control_p
cap drop thebidder
local endpd = "31mar2021"
do "modules/rdbwselect2a.ado"
use ../tmp/`sample_file_name', clear
gen thebidder = 1 if firm_treatment == 0 /*& id ~= 65459*/ & g28_plus != 21 & g28_plus != 24 & ftt_ts1p < -1.64
rddelta1pgp "provide_table" "2011" "." "before" "Before" "vsmall" "td(1apr2015)" "td(15feb2019)" "onebw" "msetwo"
est store before_p_control
rddelta1pgp "provide_table" "2011" "." "after" "After" "vsmall" "td($firstday_after)" "td(`endpd')" "onebw" "msetwo"
est store after_p_control

graph combine before after, xsize(6) ysize(4) /*note("by `endpd'")*/ graphregion(c(white)) ///
	title("Control", size(medlarge)) scale(1.1) imargin(small) name(control_p)
graph export "../graph/Controlfirms_p_by`endpd'_condition_$firstday_after.png", as(png) width(4096) replace



estout before_p_treatment after_p_treatment before_p_control after_p_control using ../tables/main_rd_test_p.tex, replace ///
	cells(none) ///
	stats(tau_bc_r se_tau_rb h_r /*b_l *kernel bwselect*/ N_r, fmt(/*%6.0g*/3  3 3 /*3 0 0*/ "%9.0fc",star(tau_bc_r)) ///
		labels(`"\raisebox{0mm}{$\hat{\beta}$}"' `" "' `"\it{h}"' `"Obs."') layout(@ (@) @ @) ) 

